package com.jeesite.modules.entity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import jakarta.validation.constraints.DecimalMin;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;

import java.io.Serial;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 捐赠记录实体类
 * @author LaVenderGong
 * @version 2025-08-16
 */
@Table(name="donationRecords", alias="a", label="捐赠记录", columns={
        @Column(name="id", attrName="id", label="ID", isPK=true, isInsert=true, isUpdate=false),
        @Column(name="donor_id", attrName="donorId", label="捐赠者ID"),
        @Column(name="donor_name", attrName="donorName", label="捐赠者姓名", queryType=QueryType.LIKE),
        @Column(name="game_account_id", attrName="gameAccountId", label="游戏账号ID"),
        @Column(name="game_nickname", attrName="gameNickname", label="游戏昵称", queryType=QueryType.LIKE),
        @Column(name="amount", attrName="amount", label="捐赠金额"),
        @Column(name="donate_date", attrName="donateDate", label="捐赠时间"),
        @Column(name="message", attrName="message", label="留言"),
        @Column(name="contact_info", attrName="contactInfo", label="联系方式"),
        @Column(name="payment_method", attrName="paymentMethod", label="支付方式"),
        @Column(name="payment_status", attrName="paymentStatus", label="支付状态"),
        @Column(name="transaction_id", attrName="transactionId", label="交易号"),
        @Column(name="payment_order_id", attrName="paymentOrderId", label="支付订单号"),
}, orderBy="a.donate_date DESC")
public class DonationRecord extends DataEntity<DonationRecord> {

    @Serial
    private static final long serialVersionUID = 1L;

    private Long donorId;                    // 捐赠者ID
    private String donorName;                // 捐赠者姓名
    private String gameAccountId;            // 游戏账号ID
    private String gameNickname;             // 游戏昵称
    private BigDecimal amount;               // 捐赠金额
    private Date donateDate;                 // 捐赠时间
    private String message;                  // 留言
    private String contactInfo;              // 联系方式
    private String paymentMethod;            // 支付方式
    private String paymentStatus;            // 支付状态
    private String transactionId;            // 交易号
    private String paymentOrderId;           // 支付订单号

    // 支付状态常量
    public static final String STATUS_PENDING = "PENDING";     // 待支付
    public static final String STATUS_PAID = "PAID";          // 已支付
    public static final String STATUS_FAILED = "FAILED";      // 支付失败
    public static final String STATUS_REFUNDED = "REFUNDED";  // 已退款

    public DonationRecord() {
        this(null);
    }

    public DonationRecord(String id) {
        super(id);
    }

    @JsonSerialize(using = ToStringSerializer.class)
    public Long getDonorId() {
        return donorId;
    }

    public void setDonorId(Long donorId) {
        this.donorId = donorId;
    }

    @Size(min=0, max=100, message="捐赠者姓名长度不能超过 100 个字符")
    public String getDonorName() {
        return donorName;
    }

    public void setDonorName(String donorName) {
        this.donorName = donorName;
    }

    @Size(min=0, max=100, message="游戏账号ID长度不能超过 100 个字符")
    public String getGameAccountId() {
        return gameAccountId;
    }

    public void setGameAccountId(String gameAccountId) {
        this.gameAccountId = gameAccountId;
    }

    @Size(min=0, max=100, message="游戏昵称长度不能超过 100 个字符")
    public String getGameNickname() {
        return gameNickname;
    }

    public void setGameNickname(String gameNickname) {
        this.gameNickname = gameNickname;
    }

    @NotNull(message="捐赠金额不能为空")
    @DecimalMin(value = "0.01", message = "捐赠金额必须大于0")
    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Date getDonateDate() {
        return donateDate;
    }

    public void setDonateDate(Date donateDate) {
        this.donateDate = donateDate;
    }

    @Size(min=0, max=500, message="留言长度不能超过 500 个字符")
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Size(min=0, max=200, message="联系方式长度不能超过 200 个字符")
    public String getContactInfo() {
        return contactInfo;
    }

    public void setContactInfo(String contactInfo) {
        this.contactInfo = contactInfo;
    }

    @Size(min=0, max=50, message="支付方式长度不能超过 50 个字符")
    public String getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(String paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    @Size(min=0, max=20, message="支付状态长度不能超过 20 个字符")
    public String getPaymentStatus() {
        return paymentStatus;
    }

    public void setPaymentStatus(String paymentStatus) {
        this.paymentStatus = paymentStatus;
    }

    @Size(min=0, max=100, message="交易号长度不能超过 100 个字符")
    public String getTransactionId() {
        return transactionId;
    }

    public void setTransactionId(String transactionId) {
        this.transactionId = transactionId;
    }

    @Size(min=0, max=100, message="支付订单号长度不能超过 100 个字符")
    public String getPaymentOrderId() {
        return paymentOrderId;
    }

    public void setPaymentOrderId(String paymentOrderId) {
        this.paymentOrderId = paymentOrderId;
    }

    /**
     * 检查是否已支付
     */
    public boolean isPaid() {
        return STATUS_PAID.equals(this.paymentStatus);
    }

    /**
     * 检查是否待支付
     */
    public boolean isPending() {
        return STATUS_PENDING.equals(this.paymentStatus);
    }
}
